package dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;



import javax.persistence.Query;
import org.springframework.stereotype.Repository;


import pojo.Customer;
import dao.CustomerDao;
@Repository(value="customerDao")
public class CustomerDaoImpl implements CustomerDao {
	@PersistenceContext(name="un")
	private EntityManager manager;
	@Override
	public Customer addCustomer(Customer c) {
		System.out.println(manager);
		manager.persist(c);
		return c;
	}

	@Override
	public Customer findCustomerByCnameAndPassword(String cname, String password) {
		Query query =  manager.createQuery("select c from Customer c where c.cname=?1 and c.password=?2 ");
		query.setParameter(1,cname);
		query.setParameter(2, password);
		Customer customer = (Customer) query.getSingleResult();
		return customer;
	}

}
